package loengud.w16;

public class ExceptionExample {

	/**
	 * Occurs when there are no free room
	 * for the exam (maximum number of students
	 * are registered).
	 */
	static class ExamFullException extends Exception {
		public ExamFullException(String message) {
			super(message);
		}
	}
	
	/**
	 * General exception for exam registration.
	 *
	 */
	static class ExamRegistrationException extends Exception {
		public ExamRegistrationException(String message) {
			super(message);
		}
	}
	
	/**
	 * A specific type of registration exception:
	 * when the exam is not allowed for the student.
	 */
	static class ExamNotAllowedException extends ExamRegistrationException {
		public ExamNotAllowedException(String message) {
			super(message);
		}
	}
	
	/**
	 * A specific type of registration exception:
	 * the deadline for the registration is over
	 */
	static class ExamDeadlineOverException extends ExamRegistrationException {
		public ExamDeadlineOverException(String message) {
			super(message);
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		try {
			registerToExam();
		} catch (ExamFullException e) {
			System.out.println("Sorry, there is no room in this exam");
		} catch (ExamDeadlineOverException e) {
			System.out.println("Sorry, the deadline for the registration is over");
		} catch (ExamNotAllowedException e) {
			System.out.println("Sorry, you are not allowed to take this exam.");
			System.out.println("The reason: " + e.getMessage());
		} catch (ExamRegistrationException e) {
			System.out.println("Sorry, there was a problem with registration");
			System.out.println("Information: " + e.getMessage());
		}
	}

	public static void registerToExam() 
	throws ExamFullException, ExamRegistrationException,
	ExamDeadlineOverException, ExamNotAllowedException {
		// to stuff here
		throw new ExamNotAllowedException("Student too old");
	}
}
